layui.use('element', function(){
  var element = layui.element;

  //一些事件监听
  element.on('tab(demo)', function(data){
    console.log(data);
  });
});


new Vue({
    el:'#app',
    data:{
        shopid : 0,
        shoptype:-1,
        shopname:'',
        mtlst : [],
        elelst :[],
        codeshoplst : [],
        allshoplst : [],
        mtShopNum:0,
        eleShopNum:0,
        codeShopNum:0,
        allShopNum : 0,
        logs :[],
        sectionindex : 0,
        plans : [],
        tomorrowplans:[],
        checkResult:[],
        exceptionList:[],
        mtshopstatus : [],
        eleshopstatus :[],
        mtdeletedshops :[],
        eledeletedshops:[],
        iplst:[],
        researchList : [],
        settings:{
            biddingtimeindex : 1,
            isenable : false,
            guard : false,
            busyTimeLock : false,
            historyMode : false,
            lock : false,
            acquirepara : false,
            account : "",
            allExposureRate : 0,
            budget:0,
            shopname : "",
            shipTime : "",
            targetExposure : 0,
            controlRate : 0,
            baseRate : 0,
            createTime:"",
            nextExposureRate : 1,
            todayExposureRate : 1,
            orderList1:[],
            orderList2:[],
            orderList3:[],
            orderList4:[],
            adTimeList:[],
            percent : 0,
            invalidPercent : false,
            daysAvgPrice : 0,
            busyOrderRate : 0,
            idleMinPrice : 0,
            busyMaxPrice : 0,
            busyMinPrice : 0,
            idleInfoList:[],
            busyInfoList : [],
            idleOrderRateList:[],
            idleMaxPriceList:[],
            advicemin : 0,
            advicemax : 0,
            advicebudget : 0,
            advicetarget : 0,
            idleExposureRate : 0,
            nearExposure : 0, //近似曝光值，给前端参考值
            isCreating : false,
            lastEditTime : '',
        },
        biddingdatalist : [],
        orderList:[],
        pcshoplst:[],
        pcshopnum:0,
        ips:'',
        errortip:false,
    },
    filters:{
        numFilter (value){
            let realVal = ""
            if(value){
                realVal = parseFloat(value).toFixed(4)
            }else{
                realVal = "--"
            }
            return realVal
        }
    },
    created(){
        var that = this
        axios({
            method:'get',
            url: 'http://47.111.126.241/api/v1/getAllShop',
        }).then(function(response){
            result = response.data.data
            that.mtlst =  result[0]
            that.mtShopNum = that.mtlst.length
            that.elelst = result[1]
            that.eleShopNum = that.elelst.length

            axios({
                method:'get',
                url: 'https://wmgj.qitianmeishi.com:9090/mp/getAll',
            }).then(function(response){
                result = response.data.data.mp
                for(var m = 0; m < result.length; m ++){
                    if(result[m].name != null && result[m].name != ''){
                        that.allshoplst.push(result[m])
                    }

                }
                that.allShopNum = that.allshoplst.length
                for(var i = 0; i < that.allshoplst.length; i ++ ){
                    if(that.allshoplst[i].code == 1){
                        //寻找这个店铺的shopid
                        for(var k = 0; k < that.mtlst.length; k ++){
                            if(that.mtlst[k].account ==that.allshoplst[i].userName ){
                                that.allshoplst[i].shopId = that.mtlst[k].id
                                break
                            }
                        }
                        that.codeshoplst.push(that.allshoplst[i])
                    }
                }
                that.codeShopNum = that.codeshoplst.length
                that.pcshoplst = response.data.data.pc
                that.pcshopnum = response.data.data.pc.length
            });
        });

    },
    mounted(){

    },
    watch:{
        'settings.percent'(newName,oldName){
            if (oldName != 0){
                console.log("划分订单的百分比改变")
                if(this.busyTimeLock){
                    layer.msg('忙时已锁定!');
                }else{
                    this.settings.idleInfoList = []
                    this.settings.busyInfoList = []
                    var orderList = this.settings.orderList1.concat(this.settings.orderList2).concat(this.settings.orderList3).concat(this.settings.orderList4)
                    var ordersum = 0
                    for(var i = 0; i < orderList.length; i++){
                        ordersum += orderList[i]
                    }

                    var blist = []
                    var ilist = []
                    for(var i = 1; i <= 48; i++){
                        if(orderList[i-1] / ordersum >= this.settings.percent / 100){
                            //忙时
                            blist.push(i)
                        }else{
                             //闲时
                             ilist.push(i)
                        }
                    }
                    //开始计算闲时是如何分布的
                    bstart = ilist[0]
                    count = 0
                    index = 0
                    for(var i = 0; i < ilist.length - 1;i++){
                        count = count + 1
                        if(ilist[i] + 1 == ilist[i+1]){
                        }else{
                            if(count - index == 1){
                                st = this.getTime(bstart - 1)
                                en = this.getTime(bstart)
                                if (st == -99999 || en == -99999){
                                    this.settings.invalidPercent = true
                                    break
                                }
                                this.settings.idleInfoList.push(st + "-" + en)
                                index = count
                                bstart = ilist[i + 1]
                            }else{
                                bend = ilist[i]
                                st = this.getTime(bstart - 1)
                                en = this.getTime(bend)
                                if (st == -99999 || en == -99999){
                                    this.settings.invalidPercent = true
                                    break
                                }
                                this.settings.idleInfoList.push(st + "-" + en)
                                bstart = ilist[i + 1]
                            }
                        }
                    }

                    bend = ilist[ilist.length - 1]

                    st = this.getTime(bstart - 1)
                    en = this.getTime(bend)
                    if (st == -99999 || en == -99999){
                        this.settings.invalidPercent = true
                        this.settings.idleInfoList = []
                    }else{
                        this.settings.idleInfoList.push(st + "-" + en)
                        this.settings.invalidPercent = false
                    }
                    //计算忙时的分布
                    bstart = blist[0]
                    count = 0
                    index = 0
                    for(var i = 0; i < blist.length - 1;i++){
                        count = count + 1
                        if(blist[i] + 1 == blist[i+1]){
                        }else{
                            if(count - index == 1){
                                st = this.getTime(bstart - 1)
                                en = this.getTime(bstart)
                                if (st == -99999 || en == -99999){
                                    this.settings.invalidPercent = true
                                    break
                                }
                                this.settings.busyInfoList.push(st + "-" + en)
                                index = count
                                bstart = blist[i + 1]
                            }else{
                                bend = blist[i]
                                st = this.getTime(bstart - 1)
                                en = this.getTime(bend)
                                if (st == -99999 || en == -99999){
                                    this.settings.invalidPercent = true
                                    break
                                }
                                this.settings.busyInfoList.push(st + "-" + en)
                                bstart = blist[i + 1]
                            }
                        }
                    }

                    bend = blist[blist.length - 1]

                    st = this.getTime(bstart - 1)
                    en = this.getTime(bend)
                    if (st == -99999 || en == -99999){
                        this.settings.invalidPercent = true
                        this.settings.busyInfoList = []
                    }else{
                        this.settings.busyInfoList.push(st + "-" + en)
                        this.settings.invalidPercent = false
                    }
                }
            }
        },
        'settings.idleInfoList'(newName,oldName){
            if(oldName.length!=0 && newName.length != 0){
                var percent = this.settings.percent + ""
                if(percent.charAt(percent.length - 1) != '.'){
                    console.log("闲时分布发生了改变")
                    layer.msg('闲时分布发生变化，可能需要重新获取闲时最高价。');
                }
            }

        },
        'settings.budget'(newName,oldName){
            if (this.settings.advicetarget != 0){
                this.settings.targetExposure =  Math.floor(this.settings.budget / (this.settings.advicebudget / this.settings.advicetarget))
                console.log("预算值改变:"+this.settings.targetExposure)
                this.settings.nearExposure =  Math.floor(this.settings.budget / (this.settings.advicebudget / this.settings.advicetarget) * this.settings.idleExposureRate * this.settings.todayExposureRate)
                var orderList = this.settings.orderList1.concat(this.settings.orderList2).concat(this.settings.orderList3).concat(this.settings.orderList4)
                var ordersum = 0
                for(var i = 0; i < orderList.length; i++){
                    ordersum += orderList[i]
                }

                var blist = []
                var ilist = []
                for(var i = 1; i <= 48; i++){
                    if(orderList[i-1] / ordersum >= this.settings.percent / 100){
                        //忙时
                        blist.push(orderList[i-1])
                    }else{
                         //闲时
                         ilist.push(orderList[i-1])
                    }
                }

                var busyOrderNum = 0
                var idleOrderNum = 0
                for(var i = 0; i < blist.length; i++){
                    busyOrderNum += blist[i]
                }
                for(var i = 0; i < ilist.length; i++){
                    idleOrderNum += ilist[i]
                }

                be = this.settings.nearExposure * (busyOrderNum / (busyOrderNum + idleOrderNum))
                ie = this.settings.nearExposure * (idleOrderNum / (busyOrderNum + idleOrderNum))
                be = be / this.settings.idleExposureRate
                this.settings.nearExposure = parseInt(be + ie)

            }
        },
        'settings.idleExposureRate'(newName,oldName){
            if (this.settings.advicetarget != 0){
                this.settings.nearExposure =  Math.floor(this.settings.budget / (this.settings.advicebudget / this.settings.advicetarget) * this.settings.idleExposureRate * this.settings.todayExposureRate)
                console.log("nearExposure : "+this.settings.nearExposure)
                var orderList = this.settings.orderList1.concat(this.settings.orderList2).concat(this.settings.orderList3).concat(this.settings.orderList4)
                var ordersum = 0
                for(var i = 0; i < orderList.length; i++){
                    ordersum += orderList[i]
                }

                var blist = []
                var ilist = []
                for(var i = 1; i <= 48; i++){
                    if(orderList[i-1] / ordersum >= this.settings.percent / 100){
                        //忙时
                        blist.push(orderList[i-1])
                    }else{
                         //闲时
                         ilist.push(orderList[i-1])
                    }
                }

                var busyOrderNum = 0
                var idleOrderNum = 0
                for(var i = 0; i < blist.length; i++){
                    busyOrderNum += blist[i]
                }
                for(var i = 0; i < ilist.length; i++){
                    idleOrderNum += ilist[i]
                }

                be = this.settings.nearExposure * (busyOrderNum / (busyOrderNum + idleOrderNum))
                ie = this.settings.nearExposure * (idleOrderNum / (busyOrderNum + idleOrderNum))
                be = be / this.settings.idleExposureRate
                this.settings.nearExposure = parseInt(be + ie)
            }
        },
        'settings.advicetarget'(newName,oldName){
            if (this.settings.advicetarget != 0){
                this.settings.targetExposure =  Math.floor(this.settings.budget / (this.settings.advicebudget / this.settings.advicetarget))

                this.settings.nearExposure =  Math.floor(this.settings.budget / (this.settings.advicebudget / this.settings.advicetarget) * this.settings.idleExposureRate * this.settings.todayExposureRate)
                var orderList = this.settings.orderList1.concat(this.settings.orderList2).concat(this.settings.orderList3).concat(this.settings.orderList4)
                var ordersum = 0
                for(var i = 0; i < orderList.length; i++){
                    ordersum += orderList[i]
                }

                var blist = []
                var ilist = []
                for(var i = 1; i <= 48; i++){
                    if(orderList[i-1] / ordersum >= this.settings.percent / 100){
                        //忙时
                        blist.push(orderList[i-1])
                    }else{
                         //闲时
                         ilist.push(orderList[i-1])
                    }
                }

                var busyOrderNum = 0
                var idleOrderNum = 0
                for(var i = 0; i < blist.length; i++){
                    busyOrderNum += blist[i]
                }
                for(var i = 0; i < ilist.length; i++){
                    idleOrderNum += ilist[i]
                }

                be = this.settings.nearExposure * (busyOrderNum / (busyOrderNum + idleOrderNum))
                ie = this.settings.nearExposure * (idleOrderNum / (busyOrderNum + idleOrderNum))
                be = be / this.settings.idleExposureRate
                this.settings.nearExposure = parseInt(be + ie)

            }
        },
        'ips'(newName,oldName){
            if(newName.indexOf("，") != -1 || newName.indexOf("：") != -1 || newName.indexOf("【") != -1 || newName.indexOf("（") != -1){
                console.log("不得使用中文符号")
                this.errortip = true
            }else
            {
                this.errortip = false
            }
        },
    },
    methods:{
        getlog:function (id,shoptype,shopindex,name) {
            this.shopid = id
            this.shoptype = shoptype
            this.shopname = name


            if(this.sectionindex == 1 || this.sectionindex == 0 || this.sectionindex == 11 || this.sectionindex == 13){
                this.sectionindex = 1
                var that = this
                var index = layer.load(1);
                axios({
                    method:'get',
                    url: 'http://47.111.126.241/api/v1/getShopLogs',
                    params:{
                        id : id
                    }
                }).then(function(response){
                    layer.close(index);
                    if(response.data.code == 200){
                            that.logs = response.data.data
                            layer.msg('获取成功', {
                                icon: 1,
                                time: 2000
                            },function(){
                            });
                        }
                });
            }else if(this.sectionindex == 2){
                // 更换店铺数据需要重新初始化
                this.settings.idleInfoList = []
                this.settings.advicetarget = 0
                this.settings.advicebudget = 0
                this.settings.nearExposure = 0
                this.settings.budget = 0

                this.setting()
            }else if(this.sectionindex == 3){
                this.getplan()
            }else if(this.sectionindex == 4){
                this.getOrderList()
            }else if(this.sectionindex == 5){
                this.getshopstatus()
            }else if(this.sectionindex == 6){
                this.checkreport()
            }else if(this.sectionindex == 7){
                this.checkbug()
            }else if(this.sectionindex == 8){
                this.getdeletedshop()
            }else if(this.sectionindex == 9){
                this.research()
            }else if(this.sectionindex == 10){
                this.getBiddingData()
            }

        },
        getplan:function(){
            if(this.shopid == 0){
                layer.msg("请先选择左侧店铺");
            }else{
                var index = layer.load(1);
                this.sectionindex=3
                var that = this
                axios({
                    method:'get',
                    url: 'http://47.111.126.241/api/v1/bidding/target/getplans',
                    params:{
                        id : that.shopid
                    }
                    }).then(function(response){
                        layer.close(index);
                        if(response.data.code == 200){
                            that.plans = response.data.data[0]
                            that.tomorrowplans = response.data.data[1]
                            layer.msg('获取成功', {
                                icon: 1,
                                time: 2000
                            },function(){
                            });
                        }else{
                            layer.msg('获取失败', {
                                icon: 2,
                                time: 2000
                            },function(){
                            });
                        }

                });
            }

        },
        checkreport:function () {
            var index = layer.load(1);
            this.sectionindex = 6
            var that = this
            axios({
                method:'get',
                url: 'http://47.111.126.241/api/v1/admin/reportCheck',

            }).then(function(response){
                layer.close(index);
                if(response.data.code == 200){
                    that.checkResult =  response.data.data
                    layer.msg('获取成功', {
                        icon: 1,
                        time: 2000
                    },function(){
                    });
                }else{
                    layer.msg('获取失败', {
                        icon: 2,
                        time: 2000
                    },function(){
                    });
                }
            });
        },
        checkbug:function () {
            var index = layer.load(1);
            this.sectionindex = 7
            var that = this
            axios({
                method:'get',
                url: 'http://47.111.126.241/api/v1/admin/shop/checkBug',
            }).then(function(response){
                layer.close(index)
                if(response.data.code == 200){
                    result = response.data.data
                    that.exceptionList = result
                    layer.msg('获取成功', {
                        icon: 1,
                        time: 2000
                    },function(){
                    });
                }else{
                    layer.msg('获取失败', {
                        icon: 2,
                        time: 2000
                    },function(){
                    });
                }


            });

        },
        getshopstatus:function () {
            var index = layer.load(1);
            this.sectionindex = 5
            var that = this
            axios({
                method:'get',
                url: 'http://47.111.126.241/api/v1/shop/checkOut',
            }).then(function(response){
                layer.close(index);
                if(response.data.code == 200){
                    result = response.data
                    that.mtshopstatus = result.data.mtShops
                    that.eleshopstatus = result.data.eleShops
                    layer.msg('获取成功', {
                        icon: 1,
                        time: 2000
                    },function(){
                    });
                }else{
                    layer.msg('获取失败', {
                        icon: 2,
                        time: 2000
                    },function(){
                    });
                }

           });
        },
        getdeletedshop:function () {
            this.sectionindex = 8
            var that = this
            axios({
                method:'get',
                url: 'http://47.111.126.241/api/v1/shop/getDeletedShop',
            }).then(function(response) {
                result = response.data
                that.mtdeletedshops = result.data.mt
                that.eledeletedshops = result.data.ele
            })
        },
        research:function () {
            var index = layer.load(1);
            this.sectionindex = 9
            var that = this
            axios({
                method:'get',
                url: 'http://47.111.126.241/api/v1/shop/getResearch',
            }).then(function(response) {
                layer.close(index);
                if(response.data.code == 200){
                    that.researchList = response.data.data
                    layer.msg('获取成功', {
                        icon: 1,
                        time: 2000
                    },function(){

                    });
                }else{
                    layer.msg('获取失败', {
                        icon: 2,
                        time: 2000
                    },function(){

                    });
                }

            })
        },
        setting:function () {
            if(this.shopid == 0){
                layer.msg("请先选择左侧店铺")
            }else{
                var index = layer.load(1);
                this.sectionindex = 2
                var that = this
                axios({
                    method:'get',
                    url: 'http://47.111.126.241/api/v1/getSuggestParam',
                    params:{
                        shopId : that.shopid,
                        shopType : that.shoptype
                    }
                }).then(function(response){
                    if (response.data.code == 200){
                        response = response.data.data
                        that.settings.advicemin = response.minPrice
                        that.settings.advicemax = response.maxPrice
                        that.settings.advicebudget = response.budget
                        that.settings.advicetarget = response.targetExposure
                    }else{
                        layer.msg("暂无建议值")
                    }

                });
                axios({
                    method:'get',
                    url: 'http://47.111.126.241/api/v1/shop/newGetShopInfo',
                    params:{
                        shopId : that.shopid,
                        shopType : that.shoptype
                    }
                }).then(function(response) {
                    layer.close(index)
                    result = response.data.data

                    that.settings.isenable = result.isenable == 1 ? true:false
                    that.settings.guard = result.guard == 1 ? true:false
                    that.settings.busyTimeLock = result.busyTimeLock == 1 ? true:false
                    that.settings.historyMode = result.historyMode == 1 ? true:false
                    that.settings.lock = result.lock == 1 ? true:false

                    that.settings.account = result.account
                    that.settings.allExposureRate = result.allExposureRate
                    that.settings.shopname = result.shopname
                    that.settings.shipTime = result.shipTime
                    that.settings.targetExposure = result.targetExposure

                    that.settings.createTime = result.createTime
                    that.settings.lastEditTime = result.lastEditTime
                    that.settings.budget = result.budget

                    that.settings.controlRate = result.controlRate
                    that.settings.baseRate = result.baseRate

                    that.settings.orderList1 = result.orderList1
                    that.settings.orderList2 = result.orderList2
                    that.settings.orderList3 = result.orderList3
                    that.settings.orderList4 = result.orderList4

                    that.settings.nextExposureRate = result.nextExposureRate
                    that.settings.todayExposureRate = result.todayExposureRate
                    that.settings.idleExposureRate = result.idleExposureRate
                    //处理推广时间段
                    adTimeList = result.adTimeList
                    that.settings.biddingtimeindex = adTimeList.length
                    that.settings.adTimeList = []
                    for(var i = 0; i < adTimeList.length;i++){
                        adTimeItem = [new Date(2019,12,31, adTimeList[i].sh, adTimeList[i].sm),new Date(2019,12,31, adTimeList[i].eh, adTimeList[i].em)]
                        that.settings.adTimeList.push(adTimeItem)
                    }

                    that.settings.percent = result.percent
                    that.settings.daysAvgPrice = result.daysAvgPrice
                    that.settings.busyOrderRate = result.busyOrderRate == '' ? '待获取' : result.busyOrderRate

                    that.settings.idleMinPrice = result.idleMinPrice
                    that.settings.busyMaxPrice = result.busyMaxPrice
                    that.settings.busyMinPrice = result.busyMinPrice

                    that.settings.idleInfoList = result.idleInfoList
                    that.settings.busyInfoList = result.busyInfoList
                    that.settings.idleOrderRateList = result.idleOrderRateList
                    that.settings.idleMaxPriceList = result.idleMaxPriceList


                });
            }
        },
        getBiddingData:function(){
            if(this.shopid == 0){
                layer.msg("请先选择左侧店铺")
            }else{
                var index = layer.load(1);
                this.sectionindex = 10
                var that = this
                axios({
                    method:'get',
                    url: 'http://47.111.126.241/api/v1/admin/getBiddingData',
                    params:{
                        shopid : that.shopid
                    },
                }).then(function(response) {
                    layer.close(index);
                    if(response.data.code == 200){
                        that.biddingdatalist = response.data.data
                        layer.msg('获取成功', {
                            icon: 1,
                            time: 2000
                        },function(){

                        });
                    }else{
                        that.biddingdatalist = []
                        layer.msg('获取失败', {
                            icon: 2,
                            time: 2000
                        },function(){

                        });
                    }


                });
            }

        },
        getTime:function(i){

            if(typeof(i) == "undefined" || isNaN(i)){
                console.log("i不合理")
                return -99999
            }else
            {
                h = ""
                if (i % 2 == 0){
                    h = Math.floor(i / 2)
                    if (h < 10){
                        h = "0" + h + ":00"
                    }else{
                        h = h + '' + ":00"
                    }
                }else{
                    h = Math.floor(i / 2)
                    if (h < 10){
                        h = "0" + h + ":30"
                    }else{
                        h = h +'' + ":30"
                    }
                }
                return h
            }

        },
        recovershop:function(shopId,shopType,shopindex){
            var that = this
            layer.open({
                content: '店铺恢复后刷新页面即可查看'
                ,btn: ['确定', '取消']
                ,yes: function(index, layero){
                    //按钮【确定】的回调
                    axios({
                        method:'get',
                        params:{
                            shopId : shopId,
                            shopType : shopType,
                            deleted : 0
                        },
                        url: 'http://47.111.126.241/api/v1/shop/changeDeletedVal',
                    }).then(function(response) {
                        if(response.data.code == 200){
                            if (shopType == 1){
                                that.mtdeletedshops.splice(shopindex,shopindex+1)
                            }else{
                                that.eledeletedshops.splice(shopindex,shopindex+1)
                            }
                            layer.msg('恢复成功', {
                                icon: 1,
                                time: 2000
                            },function(){
                            });
                        }else{
                            layer.msg('恢复失败', {
                                icon: 2,
                                time: 2000
                            },function(){
                            });
                        }


                    });
                }
                ,btn2: function(index, layero){
                    //按钮【取消】的回调

                    //return false 开启该代码可禁止点击该按钮关闭
                }
                ,cancel: function(){
                    //右上角关闭回调

                    //return false 开启该代码可禁止点击该按钮关闭
                }
            });
        },
        deleteshop:function(shopId,shopType,shopindex){
            var that = this
            layer.open({
                content: '店铺删除后可在回收站查看'
                ,btn: ['确认删除', '取消']
                ,yes: function(index, layero){
                    //按钮【确定】的回调
                    axios({
                        method:'get',
                        params:{
                            shopId : shopId,
                            shopType : shopType,
                            deleted : 1
                        },
                        url: 'http://47.111.126.241/api/v1/shop/changeDeletedVal',
                    }).then(function(response) {

                        if(response.data.code == 200){
                            if (shopType == 1){
                                that.mtshopstatus.splice(shopindex,shopindex+1)
                            }else{
                                that.eleshopstatus.splice(shopindex,shopindex+1)
                            }
                            layer.msg('删除成功', {
                                icon: 1,
                                time: 2000
                            },function(){
                            });
                        }else{
                            layer.msg('删除失败', {
                                icon: 2,
                                time: 2000
                            },function(){
                            });
                        }

                    });
                }
                ,btn2: function(index, layero){
                    //按钮【取消】的回调
                    //return false 开启该代码可禁止点击该按钮关闭
                }
                ,cancel: function(){
                    //右上角关闭回调
                    //return false 开启该代码可禁止点击该按钮关闭
                }
            });

        },
        getOrderList:function(){
            if (this.shopid == 0){
                layer.msg("请先选择左侧店铺")
            }else{
                var index = layer.load(1);
                this.sectionindex = 4;
                this.orderList = []
                var that = this
                axios({
                    method:'get',
                    url: 'http://47.111.126.241/api/v1/newGetShopOrder',
                    params:{
                        id : that.shopid
                    }
                }).then(function(response){
                    layer.close(index)
                    that.orderList = response.data.data.order_lst
                    dayList = response.data.data.day_list
                    numList = response.data.data.num_list
                    that.$nextTick(()=>{
                        var chart = Highcharts.chart('container',{
                            chart: {
                                type: 'column'
                            },
                            title: {
                                text: ''
                            },
                            xAxis: {
                                categories: dayList,
                                crosshair: true
                            },
                            yAxis: {
                                min: 0,
                                title: {
                                    text: '订单量 (单)'
                                }
                            },
                            tooltip: {
                                // head + 每个 point + footer 拼接成完整的 table
                                headerFormat: '<span style="font-size:10px">{point.key}</span><table>',
                                pointFormat: '<tr><td style="color:{series.color};padding:0">{series.name}: </td>' +
                                '<td style="padding:0"><b>{point.y:.1f} mm</b></td></tr>',
                                footerFormat: '</table>',
                                shared: true,
                                useHTML: true
                            },
                            plotOptions: {
                                column: {
                                    borderWidth: 0
                                }
                            },
                            series: [{
                                name: '近7天订单量',
                                data: numList
                            }],
                            colors: ['#009688'],
                        });
                    });

                    if(that.settings.orderList1.length != 0){
                        daysOrderList = that.settings.orderList1.concat(that.settings.orderList2).concat(that.settings.orderList3).concat(that.settings.orderList4)
                        that.$nextTick(()=>{
                        var chart = Highcharts.chart('daysOrderList', {
                            title: {
                                text: ''
                            },
                            yAxis: {
                                title: {
                                    text: '7天订单数'
                                }
                            },
                            legend: {
                                layout: 'vertical',
                                align: 'right',
                                verticalAlign: 'middle'
                            },
                            plotOptions: {
                                series: {
                                    label: {
                                        connectorAllowed: false
                                    },
                                    pointStart: 1
                                }
                            },
                            series: [
                                {
                                    name: "7天订单",
                                    data: daysOrderList
                                }
                            ],
                            colors: ['#009688'],
                            responsive: {
                                rules: [{
                                    condition: {
                                        maxWidth: 300
                                    },
                                    chartOptions: {
                                        legend: {
                                            layout: 'horizontal',
                                            align: 'center',
                                            verticalAlign: 'bottom'
                                        }
                                    }
                                }]
                            }
                        });
                    });
                    }


                });
            }



        },
        getCurrentOrder:function(dayIndex){
            this.orderList[dayIndex].null = -1;
            var that = this
            axios({
                method:'get',
                url: 'http://47.111.126.241/api/v1/shop/getCurrentOrder',
                params:{
                    id : that.shopid,
                    index : dayIndex + 1,
                }
            }).then((response)=> {

                if(response.data.code == 200){
                    this.orderList[dayIndex].null = 0
                    layer.msg('订单获取成功', {
                        icon: 1,
                        time: 2000
                    },function(){
                    });
                }else{
                    this.orderList[dayIndex].null = 1
                    layer.msg('订单获取失败', {
                        icon: 2,
                        time: 2000
                    },function(){
                    });
                }

            });
        },
        savesettings:function () {
            var that = this;
            if(that.isNumber(that.settings.budget) && that.isNumber(that.settings.targetExposure)
                && that.isNumber(that.settings.idleExposureRate) && that.isNumber(that.settings.controlRate)
                && that.isNumber(that.settings.baseRate) && that.isNumber(that.settings.idleMinPrice)
                && that.isNumber(that.settings.busyMaxPrice) && that.isNumber(that.settings.busyMinPrice)
                && that.isNumber(that.settings.nextExposureRate)
            ){
                layer.open({
                    content: '先选择保存方式'
                    ,btn: ['仅保存参数', '保存参数并生成计划', '明日生效']
                    ,btnAlign: 'l'
                    ,anim: 5
                    ,yes: function(index, layero){
                        //按钮【按钮一】的回调
                        console.log("仅保存参数")
                        //参数校验
                        layer.close(index);
                        that.enforcesettings(1,1)
                    }
                    ,btn2: function(index, layero){
                        //按钮【按钮二】的回调
                        //return false 开启该代码可禁止点击该按钮关闭
                        console.log("保存参数并生成计划")
                        that.enforcesettings(0,1)
                    }
                    ,btn3: function(index, layero){
                        //按钮【按钮三】的回调
                        //return false 开启该代码可禁止点击该按钮关闭
                        console.log("明日生效")
                        that.enforcesettings(1,0)
                    }
                    ,cancel: function(){
                        //右上角关闭回调
                        //return false 开启该代码可禁止点击该按钮关闭
                        console.log("取消")

                    }
                });
            }else{
                layer.msg('参数输入存在错误，请检查后再尝试');
            }
        },
        enforcesettings:function(onlypara,now){
            //俩个参数是:是否进保存参数，是否立即生效
            var that = this
            adTime = []
            for(var i = 0; i < that.settings.adTimeList.length; i ++){
                sh = that.settings.adTimeList[i][0].getHours() < 10 ? '0'+that.settings.adTimeList[i][0].getHours() : that.settings.adTimeList[i][0].getHours()
                sm = that.settings.adTimeList[i][0].getMinutes() < 10 ? '0'+that.settings.adTimeList[i][0].getMinutes() : that.settings.adTimeList[i][0].getMinutes()
                eh = that.settings.adTimeList[i][1].getHours() < 10 ? '0'+that.settings.adTimeList[i][1].getHours() : that.settings.adTimeList[i][1].getHours()
                em = that.settings.adTimeList[i][1].getMinutes() < 10 ? '0'+that.settings.adTimeList[i][1].getMinutes() : that.settings.adTimeList[i][1].getMinutes()
                adTime.push(
                    {
                        s:sh+':'+sm ,
                        e:eh+':'+em,
                        p : '1'
                    }
                )
            }
            adTimeStr = JSON.stringify(adTime)
            busyInfoList = JSON.stringify(this.settings.busyInfoList)
            idleInfoList = JSON.stringify(this.settings.idleInfoList)

            console.log(adTimeStr)
            axios({
                method:'get',
                url: 'http://47.111.126.241/api/v1/shop/addNewWeb',
                params:{
                    onlypara : onlypara,
                    now : now,
                    shopId : that.shopid,
                    shopType : that.shoptype,
                    account : that.settings.account,
                    budget : that.settings.budget,
                    targetExposure : that.settings.targetExposure,
                    idleExposureRate : that.settings.idleExposureRate,
                    controlRate : that.settings.controlRate,
                    baseRate :that.settings.baseRate,
                    idleMinPrice : that.settings.idleMinPrice,
                    busyMaxPrice : that.settings.busyMaxPrice,
                    busyMinPrice : that.settings.busyMinPrice,
                    nextExposureRate : that.settings.nextExposureRate,

                    isenable : that.settings.isenable == false ? 0 : 1,
                    guard : that.settings.guard == false ? 0 : 1,
                    busyTimeLock : that.settings.busyTimeLock == false ? 0 : 1,
                    historyMode : that.settings.historyMode == false ? 0 : 1,
                    lock : that.settings.lock == false ? 0 : 1,

                    adTime : adTimeStr,
                    percent : that.settings.percent,
                    busyInfoList : busyInfoList,
                    idleInfoList : idleInfoList,
                    idleOrderRateList : JSON.stringify(this.settings.idleOrderRateList),
                    idleMaxPriceList : JSON.stringify(this.settings.idleMaxPriceList),
                    busyOrderRate : that.settings.busyOrderRate == '待获取' ? '':that.settings.busyOrderRate,
                    daysAvgPrice : that.settings.daysAvgPrice,
                }
            }).then(function(response) {
                if(response.data.code == 200){

                    layer.msg('保存成功', {
                        icon: 1,
                        time: 2000
                    },function(){
                    });
                }else{
                    layer.msg('保存失败', {
                        icon: 2,
                        time: 2000
                    },function(){
                    });
                }
            });

        },
        isNumber:function(value){
            if (value === undefined || value === null || value === '') {
                return false
            }
            if (typeof(value) === 'string') {
                //正整数
                var reNumber = /^\d+$/
                //负整数
                var reNeNumber = /^-\d+$/
                //正实数
                var reRealNumber1 = /^[1-9]\d*[.]\d+$/  //非零开头
                var reRealNumber2 = /^0[.]\d+$/ //零开头
                //负实数
                var reNeRealNumber1 = /^-[1-9]\d*[.]\d+$/  //非零开头
                var reNeRealNumber2 = /^-0[.]\d+$/ //零开头

                if (reNumber.test(value)
                || reRealNumber1.test(value) || reRealNumber2.test(value)) {
                    return true
                } else {
                    return false
                }
            }
            else if (typeof(value) === 'number') {
                return true
            }
            else {
                return false
            }
        },
        getNewExposureRate:function(){
            var that = this
            adTime = []
            for(var i = 0; i < that.settings.adTimeList.length; i ++){
                adTime.push({s:that.settings.adTimeList[i][0].getHours()+':'+that.settings.adTimeList[i][0].getMinutes() ,
                        e:that.settings.adTimeList[i][1].getHours()+':'+that.settings.adTimeList[i][1].getMinutes(),
                        p : '1'}
                    )
            }
            adTimeStr = JSON.stringify(adTime)


            axios({
                method:'get',
                params:{
                    account : that.settings.account,
                    shopType : that.shoptype,
                    adTime : adTimeStr,
                    targetExposure : that.settings.targetExposure,
                    budget : that.settings.budget,
                    controlRate : that.settings.controlRate,
                    baseRate : that.settings.baseRate,
                    shopId : that.shopid,

                },
                url: 'http://47.111.126.241/api/v1/admin/getNewExposureRate',

            }).then(function(response) {
                result = response.data
                if (result.code == 200){
                    that.settings.allExposureRate = result.data
                }else{
                    layer.msg(result.message);
                }
            });
        },
        createNewPlan:function(){
            if (!this.settings.isCreating){
                if(this.settings.allExposureRate == 0){
                    layer.msg('请先获取计算曝光比，计算曝光比需要依据限制百分比和基数百分比来计算');
                }else{
                    this.settings.isCreating = true
                    var that = this
                    adTime = []
                    for(var i = 0; i < that.settings.adTimeList.length; i ++){
                        adTime.push({s:that.settings.adTimeList[i][0].getHours()+':'+that.settings.adTimeList[i][0].getMinutes() ,
                                e:that.settings.adTimeList[i][1].getHours()+':'+that.settings.adTimeList[i][1].getMinutes(),
                                p : '1'}
                            )
                    }
                    adTimeStr = JSON.stringify(adTime)
                    axios({
                        method:'get',
                        params:{
                            account : that.settings.account,
                            shopType : that.shoptype,
                            adTime : adTimeStr,
                            targetExposure : that.settings.targetExposure,
                            allExposureRate : that.allExposureRate,
                            idleExposureRate : that.settings.idleExposureRate,
                            budget : that.settings.budget
                        },
                        url: 'http://47.111.126.241/api/v1/admin/createNewPlan',
                    }).then(function(response) {
                        this.settings.isCreating = false

                        if(response.data.code == 200){
                            layer.msg('成功生成计划', {
                                icon: 1,
                                time: 2000
                            },function(){
                            });
                        }else{
                            layer.msg('生成计划失败', {
                                icon: 2,
                                time: 2000
                            },function(){
                            });
                        }
                    });
            }
            }else{
                layer.msg('正在重新生成计划!', {
                    icon: 2,
                    time: 2000
                },function(){
                });
            }
        },
        acquireIdleMaxPrice:function () {

        },
        checkip:function(){
            var index = layer.load(1);
            var that = this
            this.sectionindex = 12
            axios({
                method:'get',
                url: 'http://47.111.126.241/api/v1/admin/checkip',

            }).then(function(response){
                layer.close(index);
                if(response.data.code == 200){
                    that.iplst =  response.data.data
                    layer.msg('获取成功', {
                        icon: 1,
                        time: 2000
                    },function(){
                    });
                }else{
                    layer.msg('获取失败', {
                        icon: 2,
                        time: 2000
                    },function(){
                    });
                }
            });
        },
        sendMsg:function(){
            
        },
        changeip:function () {
            var that = this
            if(this.errortip){
                layer.msg('输入ip不正确', {
                        icon: 2,
                        time: 1000
                    },function(){
                    });
            }else{
                let ips = that.ips
                console.log(ips)
                axios({
                    method:'get',
                    url: 'http://47.111.126.241/api/v1/admin/changeip',
                    params:{
                        ips:ips,
                    },
                }).then(function(response){

                    if(response.data.code == 200){

                        layer.msg('更换成功', {
                            icon: 1,
                            time: 1000
                        },function(){
                        });
                    }else{
                        layer.msg('更换失败', {
                            icon: 2,
                            time: 1000
                        },function(){
                        });
                    }
                });
            }


        }

    },
    components:{

    }
});